package org.zfes.snowier.zbss.xzy.router.solution;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.zfes.snowier.core.data.DataSet;
import org.zfes.snowier.web.controller.BaseController;
import org.zfes.snowier.zbss.xzy.biz.solution.model.SolutionDevice;
import org.zfes.snowier.zbss.xzy.biz.solution.service.ISolutionDeviceService;
import org.zfes.snowier.zbss.xzy.solution.SolutionDeviceBindDto;
import org.zfes.snowier.zbss.xzy.solution.SolutionDto;
import org.zfes.snowier.core.data.SelectVo;
import org.zfes.snowier.core.util.ZStrUtil;
@Controller 
@RequestMapping("/manager/solutionDevice")
public class SolutionDeviceController implements BaseController {

	
	@Autowired
	private ISolutionDeviceService solutionDeviceService;
	
	 @RequestMapping(value="/loadSolutionsDeviceConfiged", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	 public @ResponseBody  Object loadSolutionsDeviceConfiged(Long deviceId){
		 List<SolutionDto> solutionList =  solutionDeviceService.loadSolutionsDeviceConfiged(deviceId);
		 return ajaxQuery("solutionListConfiged", solutionList);
	 }	

	 @RequestMapping(value="/loadSolutionsDeviceNotConfiged", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
	 public @ResponseBody  Object loadSolutionsDeviceNotConfiged(Long deviceId,String name){
		 List<SolutionDto> solutionList =  solutionDeviceService.loadSolutionsDeviceNotConfiged(deviceId,name);
		 return ajaxQuery("solutionListNotConfiged", solutionList);
	 }	
	 
	
	//@RequiresPermissions(value="solutionDevice:loadSolutionDeviceDataSet",desc="解决方案设备列表")
    @RequestMapping(value="/loadSolutionDeviceDataSet", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object loadSolutionDeviceDataSet(@RequestBody Map<String,Object> params){
	    DataSet dataSet=  solutionDeviceService.loadSolutionDeviceDataSet(params);
	    return ajaxQuery("dataSet", dataSet);
    }
	
	//@RequiresPermissions(value="solutionDevice:createSolutionDevice",desc="解决方案设备添加")
    @RequestMapping(value="/bindDeviceSolutions", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public  @ResponseBody Object bindDeviceSolutions(@RequestBody SolutionDeviceBindDto  solutionDeviceBind){
		solutionDeviceService.bindDeviceSolutions(solutionDeviceBind.getDeviceId(),solutionDeviceBind.getSolutionIds());
    	return ajaxDoneSuccess("数据操作成功 ");
    }
	
    @RequestMapping(value="/unbindDeviceSolutions", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public  @ResponseBody Object unbindDeviceSolutions(@RequestBody SolutionDeviceBindDto  solutionDeviceBind){
		solutionDeviceService.unbindDeviceSolutions(solutionDeviceBind.getDeviceId(),solutionDeviceBind.getSolutionIds());
    	return ajaxDoneSuccess("数据操作成功 ");
    }
	
    
	//@RequiresPermissions(value="solutionDevice:loadSolutionDevice",desc="解决方案设备加载")
    @RequestMapping(value="/loadSolutionDevice/{id}", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody  Object loadSolutionDevice(@PathVariable("id")Long id){
		Optional<SolutionDevice> ops = solutionDeviceService.loadSolutionDeviceById(id);
		return ajaxQuery("solutionDevice",ops);
    }


}